import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:ljy_flutter/riverpod/riverpod_user.dart';

// 用户提供者
final userProvider = StateNotifierProvider<UserNotifier, RiverpodUser?>((ref) {
  return UserNotifier();
});

// 文章提供者
final articlesProvider =
    StateNotifierProvider<ArticlesNotifier, List<RiverpodAricle>>((ref) {
      return ArticlesNotifier();
    });

// 官方教程
final counterProvider = StateProvider((ref) => 0);

// 用户状态管理类
class UserNotifier extends StateNotifier<RiverpodUser?> {
  UserNotifier() : super(null);

  void updateUser(String name) {
    state = RiverpodUser(name);
  }
}

// 文章状态管理类
class ArticlesNotifier extends StateNotifier<List<RiverpodAricle>> {
  ArticlesNotifier() : super([]);

  Future<void> fetchArticles() async {
    await Future.delayed(Duration(seconds: 2));
    state = [
      RiverpodAricle('Article 1', 'content of A 1'),
      RiverpodAricle('Article 2', 'content of A 2'),
    ];
  }
}
